home *** CD-ROM | disk | FTP | other *** search
- /*
- cvhow.cpp
-
- "How-does-it-work" window
-
- C++/Views 2.0 Demo
- Copyright (c) 1992, by Liant Software Corp.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- */
-
- #include "cvhow.h"
- #include "cvdemovw.h"
- #include "editbox.h"
- #include "font.h"
- #include "pushbttn.h"
- #include "messengr.h"
- #include "file.h"
- #include "tofmstrm.h"
- #include "notifier.h"
-
- defineClass(HowView, VDialog)
-
- HowView::HowView()
- {
- ;
- }
-
- HowView::HowView(VWindow *parent, char *tpc, char *src)
- : VDialog(5, 30, 300, 180, parent, StyleTitle | StyleCloseBox),
- overviewName(tpc),
- sourceName(src)
- {
- if (src) {
- setTitle("How it works");
- }
- else {
- setTitle("How to Order C++/Views");
- }
-
- sourceFont = new VFont("Courier New", 10);
- overviewFont = new VFont("New Times Roman", 12, TRUE);
-
- /* create ok, overview, and source buttons */
- overbttn = 0;
- srcbttn = 0;
- VPushButton *okbttn = 0;
- VPushButton *aboutbttn = 0;
-
- okbttn = new VPushButton(VFrame(25, 10, 80, 30), this, StyleDefaultButton, "Ok");
- setDefButton(okbttn);
- okbttn->uponClick(this, methodOf(VDialog, ok));
-
- /* if src is NULL, don't create Overview and Source buttons */
- if (src) {
- overbttn = new VPushButton(VFrame(130, 10, 80, 30), this, StyleDefaultButton, "Overview");
- overbttn->uponClick(this, methodOf(HowView, overviewBtn));
-
- srcbttn = new VPushButton(VFrame(235, 10, 80, 30), this, StyleDefaultButton, "Source");
- srcbttn->uponClick(this, methodOf(HowView, sourceBtn));
-
- /* enable Source button, disable Overview button */
- srcbttn->enable(TRUE);
- overbttn->enable(FALSE);
-
- if (sourceName != "cvhow.cpp") {
- /* don't show "about" button for About How About box */
- aboutbttn = new VPushButton(VFrame(340, 10, 80, 30), this, StyleDefaultButton, "About");
- aboutbttn->uponClick(this, methodOf(HowView, aboutBtn));
- }
- }
-
- /* create a edit box to display info text */
- msgBox = new VEditBox(VFrame(0.04F, 0.15F, 0.92F, 0.8F), this,
- StyleBorder | StyleVertical | StyleWordWrap | StyleReadOnly);
-
- msgBox->putText(cvTextFile->getMessage(overviewName).gets());
- msgBox->takeFocus();
- msgBox->setTabs(3);
- msgBox->setFont(overviewFont);
- }
-
- HowView::~HowView()
- {
- delete overviewFont;
- delete sourceFont;
- }
-
- boolean HowView::free()
- {
- delete this;
- return(TRUE);
- }
-
- boolean HowView::overviewBtn(VButton *b)
- /*
- "Overview" button pressed
- */
- {
- /* enable Source button, disable Overview button */
- srcbttn->enable(TRUE);
- overbttn->enable(FALSE);
-
- /* destroy the msgBox, create a new one with wordWrap */
- delete msgBox;
-
- msgBox = new VEditBox(VFrame(0.04F, 0.15F, 0.92F, 0.8F), this,
- StyleBorder | StyleVertical | StyleWordWrap | StyleReadOnly);
- msgBox->setFont(overviewFont);
- msgBox->putText(cvTextFile->getMessage(overviewName).gets());
- msgBox->setTabs(3);
-
- return(TRUE);
- }
-
- boolean HowView::sourceBtn(VButton *b)
- /*
- "Source" button pressed
- */
- {
- /* disable Source button, enable Overview button */
- srcbttn->enable(FALSE);
- overbttn->enable(TRUE);
-
- /* destroy the msgBox, create a new one with no wordWrap */
- delete msgBox;
-
- msgBox = new VEditBox(VFrame(0.04F, 0.15F, 0.92F, 0.8F), this,
- StyleBorder | StyleVertical | StyleHorizontal | StyleReadOnly);
-
- msgBox->setFont(sourceFont);
- msgBox->setTabs(3);
- msgBox->update();
-
- /* open and read the source file */
- notifier->beginWait();
-
- VFile sourceFile(sourceName);
-
- if (!sourceFile.open(ReadOnly)) {
- msgBox->putText("Unable to find source file.");
- }
- else {
- VToFromStream tofrom;
- VStream buf;
-
- /* read file into buf using VToFromStream */
- tofrom.beginScan(&sourceFile, &buf);
- tofrom.skipTo(0);
-
- /* copy text into msgBox */
- msgBox->putText(buf.gets());
-
- sourceFile.close();
- }
-
- notifier->endWait();
-
- return(TRUE);
- }
-
-
- boolean HowView::aboutBtn(VButton *b)
- /*
- "About" button pressed
- */
- {
- /* Display a message using the HowView object */
- HowView how(this, "How:About", "cvhow.cpp");
-
- /* make the how view visible */
- how.show();
-
- /* activate the dialog (as a modal dialog) */
- how.modal();
-
- return(TRUE);
- }
-